exports.order_detail = function(req,res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;
    var resultData = {};
    var o_oid = 0;

    //任务流创建
    async.waterfall([

        function(cb){

            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.search_order+"/o_no/" + restfulParams.o_no ,
                    method : 'POST',
                    data:{
                        fields:[
                            "o_oid", //机构id
                            "o_id", //订单id
                            "o_organization_name", //机构名称
                            "o_course_pic", //课程或活动的图片
                            "o_old_price", //原价
                            "o_new_price", //现价
                            "o_type", //订单的类型 0-机构活动 1-论坛活动 2-课程\r\n
                            "o_activity_type",//如果为活动， 0-拼团 1-投票 2-砍价 3-H5海报 4-助力 5-促销活动 6-微传单
                            "o_course_name", //课程或者活动名称
                            "o_pay_status",//订单支付状态 0-未支付 1-已支付 2-支付失败 3-已验证 4-已取消 5-退款中 6-已退款 7-已评价
                            "o_no",  //订单编号
                            "o_aoc_id", //关联活动或者课程ID
                            "o_create_time", //下单时间
                            "o_name", //下单人姓名
                            "o_money", //下单人姓名
                            "o_custom", 
                            "o_phone", //下单人电话
                            "o_note", //订单备注信息
                            "o_money", //订单金额
                            "o_preferential_money", //优惠金额
                            "o_pay_type",    //支付类型  0-微信支付 1-余额支付 2-混合方式 3-其他
                            "o_pay_money",    //实际付款金额
                            "o_balance_pay",    //余额支付金额
                            "o_wechat_pay",    //微信支付金额
                            "o_is_refund",    //是否为退款订单 0否1是
                            "o_is_cashback",//是否返现 0否 1是
                        ].join(",")
                    }
                },
                function (err, data) {

                    resultData.orderDetailData = data.data;
                    o_oid = data.data[0].o_oid;

                    var orderInfo = data.data[0];

                    R.SEND_HTTP(
                        req,
                        {
                            url    : CORE_APIConfig.coreAPI.search_organization_activity+"/oa_id/" +orderInfo.o_aoc_id,
                            method : 'POST',
                            data:{
                                fields:["oa_type"].join(",")
                            }
                        },
                        function (err, data) {
                            if(data.data.length>0){
                                resultData.oa_type = data.data[0].oa_type;
                            }
                            cb();
                        }
                    );
                }
            );

        },
        //查询机构的电话
        function(cb){

            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.searchOrganization+"/o_id/" +o_oid,
                    method : 'POST',
                    data:{
                        fields:[
                            "o_phone", //机构id
                        ].join(",")
                    }
                },
                function (err, data) {
                    if(data.data.length>0){
                        resultData.o_phone = data.data[0].o_phone;
                    }
                    cb();
                }
            );

        },
        function (cb) {
            //创建添加任务

            var orderListData = resultData.orderDetailData;

            var tasks = [];
            //循环节点列表
            orderListData.forEach(function (item, i) {

                //创建每一个插入任务
                tasks.push(function (cb) {

                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.search_verification_code + "/cn_ono/" + item.o_no,
                            method: 'POST',
                            data: {
                                fields: ["cn_number"].join(",")
                            }

                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return RES.response(res, false, data);
                            }
                            var verificationCodeData = data.data;

                            if(verificationCodeData.length>0){

                                item.verificationMessage = data.data[0].cn_number;

                            }else{

                                item.verificationMessage = 0;

                            }

                            cb();
                        }
                    );

                });
            });
            async.waterfall(tasks, cb);
        },

        function(cb) {
            if (resultData.orderDetailData.length > 0) {
                if (resultData.orderDetailData[0].o_is_refund == 1) {
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.search_order_refund + "/of_oid/" + resultData.orderDetailData[0].o_id,
                            method: 'POST',
                            data: {
                                fields: [
                                    "of_check_status",    //审核状态 0-未审核 1-审核通过 2-审核驳回
                                    "of_apply_time",    //申请提交时间
                                    "of_check_time",    //审核时间
                                ].join(",")
                            }
                        },
                        function (err, data) {

                            resultData.orderRefundData = data.data;
                            cb();

                        }
                    );
                }else{
                    cb()
                }

            }
        },

        ],function(err, result){
        //返回最终拼接结果
        RES.response(res,true,resultData);

    });
}